/**
 * Wihidum - Efficient Broker Hierarchy for Publish Subscribe Middleware
 *
 * License      :   Apache License 2.0
 * Home Page    :   http://code.google.com/p/wihidum/
 * Mailing List :   wihidum@googlegroups.com
 */

package lk.mrt.cse.wihidum.processor;

import org.apache.axiom.soap.*;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMElement;
import org.apache.log4j.Logger;
import lk.mrt.cse.wihidum.util.WSEventingConstants;
import lk.mrt.cse.wihidum.trace.TotalMessageTrace;

import javax.xml.namespace.QName;

public class GetMessageTraceProcessor implements Processor{

    private static final Logger logger = Logger.getLogger(GetMessageTraceProcessor.class);

    public SOAPEnvelope processMessage(SOAPEnvelope requestEnvelope) {
        try
        {
            SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
            SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();

            OMFactory factory = OMAbstractFactory.getOMFactory();

            OMElement messageTracesElement = factory.createOMElement("MessageTraces", null);
            messageTracesElement.setText(TotalMessageTrace.getMessageTrace());
            SOAPBody soapBody = soapEnvelope.getBody();
            soapBody.addChild(messageTracesElement);

            return soapEnvelope;
        }
        catch (Exception ex)
        {
            logger.error("Error in creating the SetTrace message"+ex);
            return null;
        }
    }
}
